package com.xuzhijie.pms.utils;

import com.xuzhijie.pms.entity.Administrator;

public class ThreadLocalUtil {
    private static final ThreadLocal<Administrator> ADMINISTRATOR_THREAD_LOCAL = new ThreadLocal<>();

    public static void addCurrentUser(Administrator admin){
        ADMINISTRATOR_THREAD_LOCAL.set(admin);
    }

    /**
     * 获取当前登录用户方法
     */
    public static Administrator getCurrentUser(){
        return ADMINISTRATOR_THREAD_LOCAL.get();
    }


    /**
     * 删除当前登录用户方法  在拦截器方法执行后 移除当前用户对象
     */
    public static void remove(){
        ADMINISTRATOR_THREAD_LOCAL.remove();
    }

}
